<?php

class Companies_m extends CI_Model{
	
	function __construct(){
		parent::__construct();
		$this->load->model('user');
	}
	function get_companies_by_user($client_id){
		
		$this->db->where('client_id',$client_id);
		$company = $this->db->get('companies');
		
		if($company->num_rows() > 0){
			return $company->result();
		}
		else{
			return false;
		}
		
	}
	function add_company(){
		$user = $this->user->get_user_info();
		$company = array(
			'client_id' => $user->id,
			'company_name' => $this->input->post('compname'),
			'address' => $this->input->post('address'),
			'order_by' => $this->input->post('orderby'),
			'main_contact' => $this->input->post('main_contact'),
			'website' =>$this->input->post('website'),
			'icon' => $this->input->post('icon'),
			'choice' => $this->input->post('choice'),
			'comp_full_desc' => $this->input->post('comp_full_desc'),
		);
		// adding company..
		$company_res = $this->db->insert('companies',$company); // inserting company info..
		$office = array(
			'client_id' => $user->id,
			'office_name' => $this->input->post('office_name'),
			'office_location' => $this->input->post('company_location'),
			'office_website' => $this->input->post('office_website'),
			'office_main_contact' => $this->input->post('office_main_contact'),
		);
		//adding office..
		$office_res = $this->db->insert('office',$office); // inserting office info..
		
		return ($company_res && $office_res) ? true:var_dump(mysql_error());
		
	} // end function add company..

}// end companies session..